package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        //保存
        userMapper.insert(user);
        //返回主键
        return user.getId();
    }



    //根据手机号查询用户
    @Override
    public User findByPhone(String phone) {
        //构造查询条件
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone);
        //查询
        return userMapper.selectOne(wrapper);
    }


    //修改手机号
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }
}
